﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using NS_QuangCaoTiepThiBUS;

namespace NS_QuangCaoTiepThi.QCTT.User
{
    public partial class DuyetSoanThao : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack == false)
            {
                LayDanhSachNoiDungChuaDuyet();
            }
        }

        protected void LayDanhSachNoiDungChuaDuyet()
        {
            NoiDungBUS ndBUS = new NoiDungBUS();
            gvNoiDung.DataSource = ndBUS.LayDanhSachNoiDungChuaDuyet();
            gvNoiDung.DataBind();
        }

        protected void chkChonTatCa_CheckedChanged(object sender, EventArgs e)
        {
            MyCheckBox myCheckBox = new MyCheckBox();

            if (chkChonTatCa.Checked)
            {
                myCheckBox.ChonTatCa(gvNoiDung, "chkMaNoiDung", chkChonTatCa);
            }
            else
            {
                myCheckBox.HuyTatCa(gvNoiDung, "chkMaNoiDung", chkChonTatCa);
            }
        }

        protected void gvNoiDung_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvNoiDung.PageIndex = e.NewPageIndex;

            LayDanhSachNoiDungChuaDuyet();
        }

        protected void btnDuyet_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < gvNoiDung.Rows.Count; i++)
            {
                CheckBox chkMaNoiDung = (CheckBox)(gvNoiDung.Rows[i].Cells[0].FindControl("chkMaNoiDung"));

                if (chkMaNoiDung.Checked)
                {
                    NoiDung ndDTO = new NoiDung();
                    ndDTO.MaNoiDung = gvNoiDung.DataKeys[i].Value.ToString();
                    
                    NoiDungBUS ndBUS = new NoiDungBUS();
                    ndBUS.Duyet(ndDTO);
                }
            }

            LayDanhSachNoiDungChuaDuyet();
        }

        protected void btnTroVe_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Index.aspx");
        }
    }
}